<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>webman 框架 注解路由插件 | 指尖改变世界</title><meta name="keywords" content="webman 框架 注解路由插件"><meta name="author" content="沙屿沫"><meta name="copyright" content="沙屿沫"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="webman 框架 注解路由插件">
<meta property="og:type" content="article">
<meta property="og:title" content="webman 框架 注解路由插件">
<meta property="og:url" content="http://blog.shayvmo.cn/2023/06/05/webman-route-annotation/index.html">
<meta property="og:site_name" content="指尖改变世界">
<meta property="og:description" content="webman 框架 注解路由插件">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://blog.shayvmo.cn/images/code.jpg">
<meta property="article:published_time" content="2023-06-05T07:04:07.000Z">
<meta property="article:modified_time" content="2023-06-05T07:10:45.408Z">
<meta property="article:author" content="沙屿沫">
<meta property="article:tag" content="PHP">
<meta property="article:tag" content="webman">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://blog.shayvmo.cn/images/code.jpg"><link rel="shortcut icon" href="/images/avatar.jpg"><link rel="canonical" href="http://blog.shayvmo.cn/2023/06/05/webman-route-annotation/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?5e4d1e8fcc524b4e732ea58fa9fa15f0";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'webman 框架 注解路由插件',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-06-05 15:10:45'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src= "" data-lazy-src="/images/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">74</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">42</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">15</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/images/code.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">指尖改变世界</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">webman 框架 注解路由插件</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-06-05T07:04:07.000Z" title="发表于 2023-06-05 15:04:07">2023-06-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-06-05T07:10:45.408Z" title="更新于 2023-06-05 15:10:45">2023-06-05</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/PHP/">PHP</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>5分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="webman 框架 注解路由插件"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>Github 地址：<a target="_blank" rel="noopener" href="https://github.com/shayvmo/webman-annotations">https://github.com/shayvmo/webman-annotations</a></p>
<h1 id="webman-框架-注解路由插件"><a href="#webman-框架-注解路由插件" class="headerlink" title="webman 框架 注解路由插件"></a>webman 框架 注解路由插件</h1><blockquote>
<p>使用了 doctrine/annotations 包来对代码内的注解进行解析。</p>
<p>您可以直接在控制器类或类方法定义注解，实现路由定义。</p>
</blockquote>
<p>webman框架插件地址：<a target="_blank" rel="noopener" href="https://www.workerman.net/plugin/115">https://www.workerman.net/plugin/115</a></p>
<p>站在巨人的肩膀可以看到更远，感谢 <a target="_blank" rel="noopener" href="https://www.workerman.net/plugin/52">https://www.workerman.net/plugin/52</a> 的启发。</p>
<h2 id="更新日志"><a href="#更新日志" class="headerlink" title="更新日志"></a>更新日志</h2><ul>
<li><p><strong>v1.1.1</strong></p>
<p>2023-04-11，修复发现的RequestMapping解析allow_methods问题</p>
</li>
<li><p><strong>v1.1.0</strong></p>
<p>2023-03-30，增加php8原生注解支持</p>
</li>
<li><p><strong>v1.0.1</strong></p>
<p>2023-03-27，修复发现的bug</p>
</li>
<li><p><strong>v1.0.0</strong></p>
<p>2023-03-27，发布1.0.0版本</p>
</li>
</ul>
<h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">composer require shayvmo/webman-annotations</span><br></pre></td></tr></table></figure>
<h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><h3 id="配置文件"><a href="#配置文件" class="headerlink" title="配置文件"></a>配置文件</h3><figure class="highlight php"><table><tr><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="comment">// config/plugin/shayvmo/webman-annotations/annotation.php</span></span><br><span class="line"><span class="keyword">return</span> [</span><br><span class="line">    <span class="comment">// 注解扫描路径, 只扫描应用目录下已定义的文件夹，例如： app/admin/controller 及其下级目录</span></span><br><span class="line">    <span class="string">&#x27;include_paths&#x27;</span> =&gt; [</span><br><span class="line">        <span class="string">&#x27;admin&#x27;</span></span><br><span class="line">    ],</span><br><span class="line">    <span class="comment">// requestMapping 允许的请求method</span></span><br><span class="line">    <span class="string">&#x27;allow_methods&#x27;</span> =&gt; [<span class="string">&#x27;GET&#x27;</span>, <span class="string">&#x27;POST&#x27;</span>, <span class="string">&#x27;PUT&#x27;</span>, <span class="string">&#x27;DELETE&#x27;</span>, <span class="string">&#x27;OPTIONS&#x27;</span>, <span class="string">&#x27;HEAD&#x27;</span>, <span class="string">&#x27;PATCH&#x27;</span>],</span><br><span class="line">    <span class="comment">// 忽略解析的注解名称，适用于 php7 使用 doctrine/annotations 解析</span></span><br><span class="line">    <span class="string">&#x27;ignored&#x27;</span> =&gt; [</span><br><span class="line">        <span class="string">&quot;after&quot;</span>, <span class="string">&quot;afterClass&quot;</span>, <span class="string">&quot;backupGlobals&quot;</span>, <span class="string">&quot;backupStaticAttributes&quot;</span>, <span class="string">&quot;before&quot;</span>, <span class="string">&quot;beforeClass&quot;</span>, <span class="string">&quot;codeCoverageIgnore*&quot;</span>,</span><br><span class="line">        <span class="string">&quot;covers&quot;</span>, <span class="string">&quot;coversDefaultClass&quot;</span>, <span class="string">&quot;coversNothing&quot;</span>, <span class="string">&quot;dataProvider&quot;</span>, <span class="string">&quot;depends&quot;</span>, <span class="string">&quot;doesNotPerformAssertions&quot;</span>,</span><br><span class="line">        <span class="string">&quot;expectedException&quot;</span>, <span class="string">&quot;expectedExceptionCode&quot;</span>, <span class="string">&quot;expectedExceptionMessage&quot;</span>, <span class="string">&quot;expectedExceptionMessageRegExp&quot;</span>, <span class="string">&quot;group&quot;</span>,</span><br><span class="line">        <span class="string">&quot;large&quot;</span>, <span class="string">&quot;medium&quot;</span>, <span class="string">&quot;preserveGlobalState&quot;</span>, <span class="string">&quot;requires&quot;</span>, <span class="string">&quot;runTestsInSeparateProcesses&quot;</span>, <span class="string">&quot;runInSeparateProcess&quot;</span>, <span class="string">&quot;small&quot;</span>,</span><br><span class="line">        <span class="string">&quot;test&quot;</span>, <span class="string">&quot;testdox&quot;</span>, <span class="string">&quot;testWith&quot;</span>, <span class="string">&quot;ticket&quot;</span>, <span class="string">&quot;uses&quot;</span> , <span class="string">&quot;datetime&quot;</span>,</span><br><span class="line">    ]</span><br><span class="line">];</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="一、中间件注解"><a href="#一、中间件注解" class="headerlink" title="一、中间件注解"></a>一、中间件注解</h3><blockquote>
<p>注：方法会继承类定义的中间件。</p>
</blockquote>
<p>类和方法通用，参数中间件类名，单个中间件传入字符串，多个中间件传入字符串数组。</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">use Shayvmo\WebmanAnnotations\Annotations\Middleware;</span><br><span class="line">use App\third\middleware\SignatureCheckA;</span><br><span class="line"></span><br><span class="line">// php74</span><br><span class="line">/**</span><br><span class="line"> * @Middleware(</span><br><span class="line"> *     \App\third\middleware\SignatureCheck::class,</span><br><span class="line"> * )</span><br><span class="line"> */</span><br><span class="line"> </span><br><span class="line">/**</span><br><span class="line"> * @Middleware(&#123;</span><br><span class="line"> *   SignatureCheckA::class,</span><br><span class="line"> *   \App\third\middleware\SignatureCheck::class,</span><br><span class="line"> * &#125;)</span><br><span class="line"> */</span><br><span class="line"></span><br><span class="line">// php8注解</span><br><span class="line">// 单个中间件</span><br><span class="line">#[Middleware(LimitTrafficMiddleware::class)]</span><br><span class="line">// 多个</span><br><span class="line">#[Middleware([LimitTrafficMiddleware::class, \App\third\middleware\SignatureCheck::class])]</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="二、类注解"><a href="#二、类注解" class="headerlink" title="二、类注解"></a>二、类注解</h3><p>类注解有控制器注解<code>@RestController</code>和资源路由<code>@ResourceMapping</code>。<br>资源路由和<code>webman</code>框架原有的资源路由一致。参考：<a target="_blank" rel="noopener" href="https://www.workerman.net/doc/webman/route.html">webman路由</a></p>
<h4 id="控制器注解"><a href="#控制器注解" class="headerlink" title="控制器注解"></a>控制器注解</h4><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">use Shayvmo\WebmanAnnotations\Annotations\RestController;</span><br></pre></td></tr></table></figure>

<p><code>@RestController</code>控制器注解，只有一个参数<code>prefix</code>,表示整个控制器的路由路径前缀，方法路由路径都会拼接该前缀。<br>传参可以省略键名。</p>
<ul>
<li><code>@RestController(&quot;/a&quot;)</code></li>
<li><code>@RestController(prefix=&quot;/a&quot;)</code></li>
</ul>
<p>php8注解</p>
<ul>
<li><code>#[RestController(&quot;/test1&quot;)]</code></li>
<li><code>#[RestController(path: &quot;/test2&quot;)]</code></li>
</ul>
<h4 id="资源路由注解"><a href="#资源路由注解" class="headerlink" title="资源路由注解"></a>资源路由注解</h4><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">use Shayvmo\WebmanAnnotations\Annotations\ResourceMapping;</span><br></pre></td></tr></table></figure>

<p><code>@ResourceMapping</code>资源路由注解，有<code>path</code> 和 <code>allow_methods</code>两个参数<br><code>path</code>表示资源路由的路径，<code>allow_methods</code>为指定的资源方法数组，不传指定资源方法时，使用全部资源方法<br><code>path</code>传参可以省略键名。</p>
<ul>
<li><code>@ResourceMapping(path=&quot;/dddd&quot;, allow_methods=&#123;&quot;index&quot;, &quot;show&quot;&#125;)</code></li>
<li><code>@ResourceMapping(&quot;/dddd&quot;, allow_methods=&#123;&quot;index&quot;, &quot;show&quot;&#125;)</code></li>
</ul>
<p>php8注解</p>
<ul>
<li><code>#[ResourceMapping(&quot;/test&quot;, allow_methods: [&quot;index&quot;, &quot;show&quot;])]</code></li>
<li><code>#[ResourceMapping(path: &quot;/test2&quot;, allow_methods: [&quot;index&quot;, &quot;show&quot;])]</code></li>
</ul>
<blockquote>
<p>注：如果定义了资源路由，会自动忽略类同名方法的方法注解。</p>
</blockquote>
<p>附：资源路由方法对照</p>
<table>
<thead>
<tr>
<th>请求方法</th>
<th>路径</th>
<th>类方法</th>
</tr>
</thead>
<tbody><tr>
<td>GET</td>
<td>/test</td>
<td>index</td>
</tr>
<tr>
<td>GET</td>
<td>/test/create</td>
<td>create</td>
</tr>
<tr>
<td>POST</td>
<td>/test</td>
<td>store</td>
</tr>
<tr>
<td>GET</td>
<td>/test/{id}</td>
<td>show</td>
</tr>
<tr>
<td>GET</td>
<td>/test/{id}/edit</td>
<td>edit</td>
</tr>
<tr>
<td>PUT</td>
<td>/test/{id}</td>
<td>update</td>
</tr>
<tr>
<td>DELETE</td>
<td>/test/{id}</td>
<td>destroy</td>
</tr>
<tr>
<td>PUT</td>
<td>/test/{id}/recovery</td>
<td>recovery</td>
</tr>
</tbody></table>
<h3 id="三、方法注解"><a href="#三、方法注解" class="headerlink" title="三、方法注解"></a>三、方法注解</h3><p>方法注解主要是<code>@RequestMapping</code> 以及 <code>@GetMapping</code>、<code>@PostMapping</code>、<code>@PutMapping</code>、<code>@DeleteMapping</code> 四个便捷注解。<br>定义路由路径 <code>path</code> 和请求方法<code>methods</code>。两个参数均可以传入字符串或数组。<br>例如<code>path</code>传入数组时，表示多个请求路由路径。<code>methods</code>传入数组时，表示多个请求方法。</p>
<blockquote>
<p>注：便捷注解传入路由路径<code>path</code>即可，可以省略键名<code>path</code>，无需传入<code>methods</code></p>
</blockquote>
<ul>
<li><code>@RequestMapping(path=&#123;&quot;/dddd&quot;, &quot;/dddd1&quot;&#125;, methods=&#123;&quot;get&quot;, &quot;post&quot;&#125;)</code></li>
<li><code>@GetMapping(path=&#123;&quot;/get&quot;,&quot;/get1&quot;&#125;)</code></li>
<li><code>@GetMapping(&#123;&quot;/get&quot;,&quot;/get1&quot;&#125;)</code></li>
<li><code>@PostMapping(path=&quot;/post&quot;)</code></li>
<li><code>@PutMapping(path=&quot;/put&quot;)</code></li>
<li><code>@DeleteMapping(path=&quot;/delete&quot;)</code></li>
</ul>
<p>php8注解</p>
<ul>
<li><code>#[RequestMapping(&quot;/test1&quot;, methods: &quot;get&quot;)]</code></li>
<li><code>#[RequestMapping([&quot;/test1&quot;,&quot;/test11&quot;], methods: [&quot;get&quot;, &quot;post&quot;])]</code></li>
<li><code>#[GetMapping([&quot;/get&quot;, &quot;/get1&quot;])]</code></li>
<li><code>#[PostMapping(path: &quot;/post&quot;)]</code></li>
<li><code>#[PutMapping(path: &quot;/put&quot;)]</code></li>
<li><code>#[DeleteMapping(&quot;/delete&quot;)]</code></li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">// 方法注解</span><br><span class="line">use Shayvmo\WebmanAnnotations\Annotations\RequestMapping;</span><br><span class="line">use Shayvmo\WebmanAnnotations\Annotations\GetMapping;</span><br><span class="line">use Shayvmo\WebmanAnnotations\Annotations\PostMapping;</span><br><span class="line">use Shayvmo\WebmanAnnotations\Annotations\PutMapping;</span><br><span class="line">use Shayvmo\WebmanAnnotations\Annotations\DeleteMapping;</span><br></pre></td></tr></table></figure>

<h3 id="四、示例"><a href="#四、示例" class="headerlink" title="四、示例"></a>四、示例</h3><figure class="highlight php"><table><tr><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">declare</span> (strict_types=<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">namespace</span> <span class="title">App</span>\<span class="title">third</span>\<span class="title">controller</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">use</span> <span class="title">Shayvmo</span>\<span class="title">WebmanAnnotations</span>\<span class="title">Annotations</span>\<span class="title">RestController</span>;</span><br><span class="line"><span class="keyword">use</span> <span class="title">Shayvmo</span>\<span class="title">WebmanAnnotations</span>\<span class="title">Annotations</span>\<span class="title">DeleteMapping</span>;</span><br><span class="line"><span class="keyword">use</span> <span class="title">Shayvmo</span>\<span class="title">WebmanAnnotations</span>\<span class="title">Annotations</span>\<span class="title">GetMapping</span>;</span><br><span class="line"><span class="keyword">use</span> <span class="title">Shayvmo</span>\<span class="title">WebmanAnnotations</span>\<span class="title">Annotations</span>\<span class="title">Middleware</span>;</span><br><span class="line"><span class="keyword">use</span> <span class="title">Shayvmo</span>\<span class="title">WebmanAnnotations</span>\<span class="title">Annotations</span>\<span class="title">PostMapping</span>;</span><br><span class="line"><span class="keyword">use</span> <span class="title">Shayvmo</span>\<span class="title">WebmanAnnotations</span>\<span class="title">Annotations</span>\<span class="title">PutMapping</span>;</span><br><span class="line"><span class="keyword">use</span> <span class="title">Shayvmo</span>\<span class="title">WebmanAnnotations</span>\<span class="title">Annotations</span>\<span class="title">RequestMapping</span>;</span><br><span class="line"><span class="keyword">use</span> <span class="title">Shayvmo</span>\<span class="title">WebmanAnnotations</span>\<span class="title">Annotations</span>\<span class="title">ResourceMapping</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">use</span> <span class="title">App</span>\<span class="title">third</span>\<span class="title">middleware</span>\<span class="title">SignatureCheck</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">use</span> <span class="title">support</span>\<span class="title">Request</span>;</span><br><span class="line"><span class="keyword">use</span> <span class="title">Tinywan</span>\<span class="title">LimitTraffic</span>\<span class="title">Middleware</span>\<span class="title">LimitTrafficMiddleware</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@RestController</span>(&quot;/test&quot;)</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@ResourceMapping</span>(&quot;/dddd&quot;, allow_methods=&#123;&quot;index&quot;, &quot;show&quot;&#125;)</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@Middleware</span>(SignatureCheck::class)</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ATest</span></span></span><br><span class="line"><span class="class"></span>&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">index</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="comment">// </span></span><br><span class="line">        <span class="keyword">return</span> <span class="string">&#x27;Test/index&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">show</span>(<span class="params">Request <span class="variable">$request</span>, <span class="variable">$id</span></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;Test/show <span class="subst">$id</span>&quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@GetMapping</span>(&quot;/test&quot;)</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@Middleware</span>(SignatureCheck::class)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">get</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&#x27;Test/get&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@RequestMapping</span>(methods=&#123;&quot;get&quot;, &quot;post&quot;&#125;, path=&quot;/test1&quot;)</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@Middleware</span>(&#123;</span></span><br><span class="line"><span class="comment">     *     LimitTrafficMiddleware::class,</span></span><br><span class="line"><span class="comment">     * &#125;)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">test</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&#x27;Test/test&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@PostMapping</span>(&quot;/post&quot;)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">post</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&#x27;Test/post&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@PutMapping</span>(&quot;/put&quot;)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">put</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&#x27;Test/put&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@DeleteMapping</span>(&quot;/delete&quot;)</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">delete</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function">    </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&#x27;Test/delete&#x27;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">沙屿沫</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://blog.shayvmo.cn/2023/06/05/webman-route-annotation/">http://blog.shayvmo.cn/2023/06/05/webman-route-annotation/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://blog.shayvmo.cn" target="_blank">指尖改变世界</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/PHP/">PHP</a><a class="post-meta__tags" href="/tags/webman/">webman</a></div><div class="post_share"><div class="social-share" data-image="/images/code.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/2023/05/29/nginx-reload-not-effect/"><img class="next-cover" src= "" data-lazy-src="/images/code.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">windows服务器重载nginx配置无效</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2019/11/09/function1/" title="PHP 返回一维数组中，有序组合成 N 个元素的数组"><img class="cover" src= "" data-lazy-src="/images/420e7cbd02507bcbe39236a3b384a59f17.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-09</div><div class="title">PHP 返回一维数组中，有序组合成 N 个元素的数组</div></div></a></div><div><a href="/2022/08/15/long-lat-distance/" title="【函数分享】计算两个经纬度之间的距离"><img class="cover" src= "" data-lazy-src="/images/code.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-15</div><div class="title">【函数分享】计算两个经纬度之间的距离</div></div></a></div><div><a href="/2022/08/15/my-online-log/" title="线上日志系统"><img class="cover" src= "" data-lazy-src="/images/code.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-15</div><div class="title">线上日志系统</div></div></a></div><div><a href="/2023/05/24/php-aes/" title="前后端接口传输AES加密"><img class="cover" src= "" data-lazy-src="/images/code.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-05-24</div><div class="title">前后端接口传输AES加密</div></div></a></div><div><a href="/2019/08/30/php-basic-1/" title="php常量以及数据类型"><img class="cover" src= "" data-lazy-src="/images/php.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-08-30</div><div class="title">php常量以及数据类型</div></div></a></div><div><a href="/2019/10/25/php-array/" title="php 遍历数组的几种方式"><img class="cover" src= "" data-lazy-src="/images/php.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-25</div><div class="title">php 遍历数组的几种方式</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src= "" data-lazy-src="/images/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">沙屿沫</div><div class="author-info__description">科技始终来源于人性</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">74</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">42</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">15</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/shayvmo"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">生活就像海洋，只有意志坚强的人才能到达彼岸。</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#webman-%E6%A1%86%E6%9E%B6-%E6%B3%A8%E8%A7%A3%E8%B7%AF%E7%94%B1%E6%8F%92%E4%BB%B6"><span class="toc-number">1.</span> <span class="toc-text">webman 框架 注解路由插件</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97"><span class="toc-number">1.1.</span> <span class="toc-text">更新日志</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%89%E8%A3%85"><span class="toc-number">1.2.</span> <span class="toc-text">安装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8"><span class="toc-number">1.3.</span> <span class="toc-text">使用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="toc-number">1.3.1.</span> <span class="toc-text">配置文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E4%B8%AD%E9%97%B4%E4%BB%B6%E6%B3%A8%E8%A7%A3"><span class="toc-number">1.3.2.</span> <span class="toc-text">一、中间件注解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E7%B1%BB%E6%B3%A8%E8%A7%A3"><span class="toc-number">1.3.3.</span> <span class="toc-text">二、类注解</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8E%A7%E5%88%B6%E5%99%A8%E6%B3%A8%E8%A7%A3"><span class="toc-number">1.3.3.1.</span> <span class="toc-text">控制器注解</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%B5%84%E6%BA%90%E8%B7%AF%E7%94%B1%E6%B3%A8%E8%A7%A3"><span class="toc-number">1.3.3.2.</span> <span class="toc-text">资源路由注解</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%89%E3%80%81%E6%96%B9%E6%B3%95%E6%B3%A8%E8%A7%A3"><span class="toc-number">1.3.4.</span> <span class="toc-text">三、方法注解</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9B%9B%E3%80%81%E7%A4%BA%E4%BE%8B"><span class="toc-number">1.3.5.</span> <span class="toc-text">四、示例</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/06/05/webman-route-annotation/" title="webman 框架 注解路由插件"><img src= "" data-lazy-src="/images/code.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="webman 框架 注解路由插件"/></a><div class="content"><a class="title" href="/2023/06/05/webman-route-annotation/" title="webman 框架 注解路由插件">webman 框架 注解路由插件</a><time datetime="2023-06-05T07:04:07.000Z" title="发表于 2023-06-05 15:04:07">2023-06-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/05/29/nginx-reload-not-effect/" title="windows服务器重载nginx配置无效"><img src= "" data-lazy-src="/images/code.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="windows服务器重载nginx配置无效"/></a><div class="content"><a class="title" href="/2023/05/29/nginx-reload-not-effect/" title="windows服务器重载nginx配置无效">windows服务器重载nginx配置无效</a><time datetime="2023-05-29T08:03:45.000Z" title="发表于 2023-05-29 16:03:45">2023-05-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/05/24/php-aes/" title="前后端接口传输AES加密"><img src= "" data-lazy-src="/images/code.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="前后端接口传输AES加密"/></a><div class="content"><a class="title" href="/2023/05/24/php-aes/" title="前后端接口传输AES加密">前后端接口传输AES加密</a><time datetime="2023-05-24T07:00:39.000Z" title="发表于 2023-05-24 15:00:39">2023-05-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/08/16/yar-demo/" title="Yar拓展，实现PHP的RPC服务"><img src= "" data-lazy-src="/images/code.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Yar拓展，实现PHP的RPC服务"/></a><div class="content"><a class="title" href="/2022/08/16/yar-demo/" title="Yar拓展，实现PHP的RPC服务">Yar拓展，实现PHP的RPC服务</a><time datetime="2022-08-16T09:30:43.000Z" title="发表于 2022-08-16 17:30:43">2022-08-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/08/15/my-online-log/" title="线上日志系统"><img src= "" data-lazy-src="/images/code.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="线上日志系统"/></a><div class="content"><a class="title" href="/2022/08/15/my-online-log/" title="线上日志系统">线上日志系统</a><time datetime="2022-08-15T09:03:01.000Z" title="发表于 2022-08-15 17:03:01">2022-08-15</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/images/code.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2023 By 沙屿沫</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><a href="http://www.beian.miit.gov.cn/" target="_blank" rel="noopener"><img class="icp-icon" src= "" data-lazy-src="/images/icp.png"><span>粤ICP备18133330号</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-show-text.min.js" data-mobile="false" data-text="富强,民主,文明,和谐,自由,平等,公正,法治,爱国,敬业,诚信,友善" data-fontsize="15px" data-random="false" async="async"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>